<?php
/**
Pagina Inicial do projeto de diario online
*/

require_once("main.php");

require_once("PostsPeer.php");
require_once("MenuPeer.php");

$criteria = new Criteria();
$criteria->addAscendingOrderByColumn(MenuPeer::IDMENU);
$menus = MenuPeer::doSelect($criteria);
$marray = array();
foreach($menus as $menu) {
    $marray[] = $menu->toArray();
}

$id = $_GET['id'];
$criteria = new Criteria();
$criteria->add(PostsPeer::IDPOSTS, $id);
$post = PostsPeer::doSelect($criteria);
$parray = array();

$n=0;
foreach($post as $post) {
    $qntcomentarios = $post->countComentarioss();

    $parray[$n] = $post->toArray();
    $parray[$n][qntcomentarios] = $qntcomentarios;
    $n++;
}
$comentarios = $post->getComentarioss();
$carray = array();
foreach($comentarios as $comentario){
    $carray[] = $comentario->toArray();
}

$pagina->assign('posts',$parray);
$pagina->assign('comentarios',$carray);
$pagina->assign('menus',$marray);

//echo "$<br />";
/*
echo "<pre>";
var_dump ($p);
echo "</pre>";
*/

$pagina->display("post.tpl");

?>